#include <pc.h>
#include <dpmi.h>
#include <go32.h>

#include "timer.h"
volatile int num_mili=0;
volatile int tempo_decorrido=0;

#define MIL 1000

/** Program timer (0,1,2) with mode
 */
void timer_init(int timer, int mode)
{
	outportb(timer, mode);
}

/** Load timer (0,1,2) with value
 */
void timer_load(int timer, int value)
{
	outportb(timer, LSB(value));
	outportb(timer, MSB(value));
}

/** Wait mili miliseconds, indirectly counting T0 interrupts
*/
void mili_sleep(int mili)
{
	int miliSecInic = num_mili + mili;
	while( num_mili < miliSecInic )
	{}
}

/** wait secs seconds, indirectly counting T0 interrupts
 */
void sec_sleep(int secs)
{
	mili_sleep( secs*MIL );
}
